﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using DC.Utils;
using Newtonsoft.Json;

namespace DC
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            CefSettings cefSettings = new CefSettings();
            Cef.Initialize(cefSettings);

            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            if (System.IO.File.Exists(Application.StartupPath + "\\config\\database.json"))
            {
                Utils.ServerProperty sp = JsonConvert.DeserializeObject<ServerProperty>
                    (FileHelper.ReadFile(Application.StartupPath + "\\config\\database.json"));
                Utils.Global.GlobalDB = new Utils.Database(sp);
            }
            else
            {
                MessageBox.Show("这是您第一次启动本程序，请先进行数据配置！", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Views.Form_Settings form_Settings = new Views.Form_Settings();
                form_Settings.ShowDialog();
                if (!form_Settings.saved)
                {
                    Environment.Exit(0);
                }
                else
                {
                    Utils.ServerProperty sp = JsonConvert.DeserializeObject<ServerProperty>
                        (FileHelper.ReadFile(Application.StartupPath + "\\config\\database.json"));
                    Utils.Global.GlobalDB = new Utils.Database(sp);
                }
            }
            Application.Run(new Form_Main());
        }
    }
}
